package com.cyj.dream.auth.service.impl;

import com.alibaba.excel.EasyExcel;
import com.cyj.dream.auth.listener.SysUserExcelListener;
import com.cyj.dream.auth.entity.SysUser;
import com.cyj.dream.auth.persistence.service.ITbSysUserService;
import com.cyj.dream.auth.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

/**
 * @Description: 用户服务类实现
 * @BelongsProject: DreamChardonnay
 * @BelongsPackage: com.cyj.dream.auth.service.impl
 * @Author: ChenYongJia
 * @CreateTime: 2021-10-12 08:58
 * @Email: chen87647213@163.com
 * @Version: 1.0
 */
@Slf4j
@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private ITbSysUserService iTbSysUserService;

    /**
     * 导入数据
     *
     * @param file 文件
     * @author ChenYongJia
     * @date 2021/10/12
     * @return
     */
    @Override
    public void importData(MultipartFile file){
        try {
            //文件输入流
            InputStream in=file.getInputStream();
            //调用方法进行读取
            //吧service直接注入进来为了后面能使用

            //因为在listener中不能注入service所以在这个serviceiimpl中，通过listener使service注入进去，为了在listener中能够使用service中的发方法save/
            EasyExcel.read(in, SysUser.class,new SysUserExcelListener(iTbSysUserService)).sheet().doRead();
            log.info("Excel导入成功");
        }catch(Exception e){
            e.printStackTrace();
            log.info("Excel导入失败，错误信息为：{}", e);
        }
    }


}
